﻿using System.IO.IsolatedStorage;
using System.IO;
using System.Windows;
using System;
namespace Zeus.Classes.Documents
{
    public class TextDocument : Document
    {
        private string ContentFile { get; set; }
        public string Extenstion { get; set; }
        public TextDocument(ProjectItem_Types type)
        {
            if (type == ProjectItem_Types.Text)
            {
                FilePath = "./" + Project.ProjectName + "/Text/" + FileName;
                DocType = ProjectItem_Types.Text;
            }
            else
            {
                FilePath = "./" + Project.ProjectName + "/App_Code/" + FileName;
                DocType = ProjectItem_Types.Class;
            }
            Initilize();
        }
        public void Save(string Text)
        {
            StreamWriter writer;
            IsolatedStorageFile isolated = IsolatedStorageFile.GetUserStoreForApplication();
            // Assign the writer to the store and the file TestStore.
            writer = new StreamWriter(new IsolatedStorageFileStream(
                this.FilePath, FileMode.Create,isolated));
            writer.WriteLine(Text);
            writer.Close();
        }
        public override void Save()
        {
            throw new NotImplementedException();
        }

        public override void Initilize()
        {
           
           
        }
        public string ReadFile()
        {
            IsolatedStorageFile isolated = IsolatedStorageFile.GetUserStoreForApplication();

            IsolatedStorageFileStream isolatedStorageFileStream = isolated.OpenFile(FilePath, FileMode.Open);
            StreamReader SR = new StreamReader(isolatedStorageFileStream);
            ContentFile = SR.ReadToEnd();
            SR.Close();
            return ContentFile;
        }
    }
}
